package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.League;
import com.woniu.pojo.Timetable;
import com.woniu.service.ITimetableService;
import com.woniu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zbk
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/timetable")
@Api(tags = "课程表管理")
public class TimetableController extends BaseController{

    @Autowired
    private ITimetableService timetableService;

    @ApiOperation("分页搜索")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(@PathVariable Integer currentPage,
                         @PathVariable Integer pageSize,
                         @RequestBody TimetableQueryVo timetableQueryVo){
        PageResult pageResult = timetableService.search(currentPage, pageSize, timetableQueryVo);
        return toDataResult(pageResult);
    }

    @ApiOperation("增加")
    @PostMapping
    public Result add(@RequestBody Timetable timetable){
        boolean flag = timetableService.save(timetable);
        return toResult(flag);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result edit(@RequestBody Timetable timetable){
        boolean flag = timetableService.updateById(timetable);
        return toResult(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable String id){
        boolean flag = timetableService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result queryById(@PathVariable String id){
        Timetable timetable = timetableService.getById(id);
        return toDataResult(timetable);
    }

    @ApiOperation("查询所有课程")
    @GetMapping("/all/{gymId}")
    public Result queryAll(@PathVariable String gymId){
        List<TimetableSearchVo> timetableSearchVoList = timetableService.queryAll(gymId);
        return toDataResult(timetableSearchVoList);
    }

    @ApiOperation("查询团课详情")
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable String id){
        LeagueDetailVo leagueDetailVo = timetableService.detail(id);
        return toDataResult(leagueDetailVo);
    }

    @ApiOperation("查询预约信息")
    @GetMapping("/bookMsg/{id}")
    public Result bookMsg(@PathVariable String id){
        LeagueBookVo leagueBookVo = timetableService.bookMsg(id);
        return toDataResult(leagueBookVo);
    }

}
